class Solution:
    def multiply(self, num1: str, num2: str) -> str:
        if num1=='0' or num2=='0':
            return '0'

        if len(num1)<len(num2):
            num1 , num2 = num2, num1
        num1 = list(map(int,list(num1)))
        num1.reverse()
        num2 = list(map(int, list(num2)))
        num2.reverse()

        def multiply2(x, y, off):
            stat = 0
            r = [0] * off
            for i in range(len(x)):
                c = x[i]*y+ stat
                r.append(c % 10 )
                stat = c//10

            if stat!=0:
                r.append(stat)
            return r
        def add(x, y):
            if len(x)<len(y):
                x,y = y,x
            r = []
            stat = 0
            for i in range(len(x)):
                if i>=len(y):
                    y1 = 0
                else:
                    y1 = y[i]
                c = x[i] + y1+ stat
                r.append(c % 10)
                stat = c // 10
            if stat!=0:
                r.append(stat)
            return r

        sum = [0]
        for i in range(len(num2)):
            c = multiply2(num1, num2[i], i)
            sum = add(sum, c)
            # c.reverse()
            # print(''.join(map(str, c)))
        sum.reverse()

        return ''.join(map(str, sum))


if __name__ == '__main__':
    so = Solution()
    num1 = "2925"
    num2 = "4787"
    r = so.multiply(num1, num2)
    print(r)
    print(int(num1)*int(num2))
